import Vue from 'vue'
const mutations = {
  SET_DATA(state, data) {
    const {
      phoneData,
      cartList
    } = data
    state.phoneData = phoneData
    state.cartList = cartList
  },
  // 增加购物车数量
  ADD_CART(state, good) {
    if (!good.count) {
      Vue.set(good, 'count', 1)
      state.cartList.push(good)
    } else {
      good.count++
    }
    localStorage.setItem('cartList', JSON.stringify(state.cartList))
  },
  // 减少购物车数量
  SUB_CART(state, good) {
    good.count--
    if (!good.count) {
      state.cartList.splice(state.cartList.indexOf(good), 1)
    }
    localStorage.setItem('cartList', JSON.stringify(state.cartList))
  }
}
export default mutations
